home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
bathints.zip
/
BH_08.DOC
< prev
next >
Wrap
Text File
|
1988-04-17
|
10KB
|
278 lines
BAT-HINT # 8
**************************************************************************
from the BATHINTS library... part of the BATPOWER CONFERENCE from:
THE PAINFRAME OPUS/FIDO 261/1004 LYNX OPUS/FIDO 134/27
&
Baltimore, Maryland (301) 488-7461 Cochrane, Alberta (403) 932-2750
**************************************************************************
ANSI.SYS COMMAND EXAMPLES
This BAT-HINT is comprised of an assortment of ANSI.SYS command examples,
and assumes that the user has read BAT-HINT #7 (ANSI.SYS ESCAPE SEQUENCES).
Please recall that you must install the ANSI.SYS device driver in your
config.sys file (and reboot) in order to use ANSI.SYS commands.
CURSOR CONTROL
--------------
The cursor may be easily controlled in batch files using ANSI.SYS commands.
Carefull manipulation of the cursor can provide a means whereby text may be
displayed at any location on the screen. A simple example of this control
is shown below:
center1.bat
echo off
cls
ESC[12;36H--CENTER--
Center1.bat moves the cursor to row 12 column 36 and displays the text
--CENTER-- in the middle of the screen. Simple enough. Now let's modify
this batch file to display not only --CENTER-- in the middle of the screen,
but also the words TOP and BOTTOM at their appropriate locations...
center2.bat
echo off
cls
ESC[12;36H--CENTER--ESC[;36H---TOP----ESC[24;36H--BOTTOM--
Note how more than one ANSI.SYS command may be placed on a single line so
long as each command is preceeded by an escape character and a left square
bracket. Note also that to position the cursor in row 1 the number 1 was
not necessary... only the semicolon to indicate that the number to follow is
a column designation. The ESC[#;#H command actually allows the row # range
to be 1-25. A further point to note is that it was not necessary in
center2.bat to display the lines in descending order... the center line
appeared first, then the top line and finally the bottom line. Thus by such
technique it is possible to display text anywhere in the screen at any time.
For example, using the utility KEY.COM which waits for the user to hit a key
(and optionally returns an errorlevel code equal to the ASCII DEC code of
that key), it is possible to "time" the display of text anywhere on the
screen, as shown in the next example:
center3.bat
echo off
cls
ESC[12;36H--CENTER--
key
ESC[;36H---TOP----
key
ESC[24;36H--BOTTOM--
key
The KEY.COM utility is available in the BATPOWER file area.
The next example incorporates the features of center3.bat and introduces
the use of the save cursor command (ESC[s), the erase to end of line command
(ESC[K) and the restore cursor position command (ESC[u)...
center4.bat
echo off
cls
ESC[12;36H--CENTER--ESC[s
key
ESC[;36H---TOP----
key
ESC[24;36H--BOTTOM--
key
ESC[uESC[K--center--ESC[25;1H
key
Center4.bat saves the cursor position of the text --CENTER-- ...before the
text is displayed... and later restores that position, erases line 12 from
column 36 to the end of the line, then displays the same text in lower case
and finally moves the cursor to the last line (#25) in column 1 so that the
prompt does not reappear in the midst of the display.
Similar cursor movement may be commanded using the move right, left, up and
down ANSI.SYS commands.
DISPLAY ATTRIBUTES
------------------
The text displayed by the batch file examples shown above may be changed to
high intensity (bold), blinking, reverse video, underlined and even made
invisible using the set attribute ANSI.SYS command (ESC[#m). The following
example demonstrates the use of these commands:
display1.bat
echo off
cls
echo normal
echo ESC[1mhigh intensityESC[m
echo ESC[4munderlinedESC[m
echo ESC[5mblinkingESC[m
echo ESC[7mreverseESC[m
echo ESC[8minvisibleESC[m
Note that each attribute must be turned off after it is turned on, using the
ESC[m command. An easier way to accomplish this is to incorporate the "turn
off" attribute command in the next command line, as shown below:
display2.bat
echo off
cls
echo normal
echo ESC[1mhigh intensity
echo ESC[0;4munderlined
echo ESC[0;5mblinking
echo ESC[0;7mreverse
echo ESC[0;8minvisibleESC[m
In a similar manner, several attributes may be turned on and off in a single
ANSI.SYS command, as shown below:
display4.bat
echo off
cls
echo normal
echo ESC[1mhigh intensity
echo ESC[4mhigh intensity & underlined
echo ESC[5mhigh intensity & underlined & blinking
echo ESC[7mhigh intensity & underlined & blinking & reverseESC[m
Note from display4.bat that the attribute is remembered... so that if the
previous attributes are not turned off, the next attribute specified will
incorporate all prior attributes. Display4.bat is equivalent to
display5.bat shown below:
display5.bat
echo off
cls
echo normal
echo ESC[1mhigh intensity
echo ESC[0;1;4mhigh intensity & underlined
echo ESC[0;1;4;5mhigh intensity & underlined & blinking
echo ESC[0;1;4;5;7mhigh intensity & underlined & blinking & reverseESC[m
Display5.bat differs from display4.bat only in that it manually turns off
all prior attributes (via attribute # 0) then turns the attributes on (it
also takes longer to write!). One last note... remember to turn off all
attributes before the batch file terminates as these attributes are carried
forward by DOS.
In a manner similar to that shown in the display?.bat examples (this is
where I get lazy) you can alter the foreground and background colors of the
displayed text.
DISPLAY MODE
------------
Let it be known that I accept no responsibility for damage or alteration to
any device attached or within any computer system in which the following
mode?.bat files are executed. I say this only because I haven't the
foggiest idea if switching modes with ANSI.SYS commands may damage or alter
some video cards or monitors or both. I simply haven't the resources to
check this out. The resolution and color capability of your display can be
set with ANSI.SYS commands. For example, to set your display to monchrome
and 25 rows by 40 columns (wide) display and echo the text string HELLO in
the middle of the screen (and then return to normal color mode), you could
use the following batch file:
mode1.bat
echo off
cls
echo ESC[0h
echo ESC[12;18HHELLO
key
echo ESC[3h
Note that when an ANSI.SYS mode command is issued, the display blanks...
this is the reason the batch file is paused with the KEY command, otherwise
when the mode is returned to normal color by the last line of the batch file
the display will be blanked, resulting in nothing more than a couple of
display skrinks ("skrink" is a term I use to describe the monitor state
during a mode switch and the high-pitched noise that ensues!). Once again,
other modes may be set in a similar manner with the appropriate code number.
KEY DEFINITIONS
---------------
The redefinition of keys on the keyboard is a relatively simple matter with
ANSI.SYS commands, and although such commands are not as easy to issue as
those of such programs as SUPERKEY, they are almost as powerfull and a lot
cheaper. For example, to redefine the key for the letter "a" to the letter
"b" (heaven only knows why you would want to do this!) you could create the
following batch file:
key1.bat
echo off
cls
echo ESC[97;98p
where 97 is the ASCII DEC code for the character "a" and 98 is the code for
the character "b". OK, now how to get it back to normal?... like this:
key2.bat
echo off
cls
echo ESC[97;97p
To redefine a key that was previously altered, just define it to the value
it was originally. Most people prefer to define keys that are not keys used
frequently...